''' A toy example of playing against a random agent on Limit Hold'em
'''
#coding=utf-8

# import rlcard
# from rlcard.agents import LimitholdemHumanAgent as HumanAgent
# from rlcard.agents import RandomAgent
# from rlcard.utils.utils import print_card
# from rlcard import models

import torch
# import os
# import array

# import collections
# Make environment
# env = rlcard.make('limit-holdem')
# human_agent = HumanAgent(env.num_actions)
# human_agent1 = HumanAgent(env.num_actions)
# agent_0 = RandomAgent(num_actions=env.num_actions)
model_path = "model.pth"
agent_0 = torch.load(model_path)


print(">> Limit Hold'em random agent")

class Ai(object):

    def __init__(self):
        return

    def step(self, state):
        # state = {
        # 'legal_actions': collections.OrderedDict([(1, None), (2, None), (3, None)]), 
        # 'obs': [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        #         0, 1, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 
        #         0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
        #         0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
        #         0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1,0, 0, 0, 0],
        # 'raw_obs': {'hand': ['S8', 'C2'], 'public_cards': ['H3', 'CQ', 'D6', 'SA', 'CJ'], 'all_chips': [10, 10], 'my_chips': 10, 'legal_actions': ['raise', 'fold', 'check'], 'raise_nums': [1, 1, 1, 0]},
        # 'raw_legal_actions': ['raise', 'fold', 'check'], 
        # 'action_record': [(1, 'raise'), (0, 'call'), (1, 'raise'), (0, 'call'), (1, 'raise'), (0, 'call')]
        # }

        # print("1111111state", state)
        # json_state = json.dumps(state)
        # print("json_state:", json_state)
        # state = json.loads(json_str)
        # action_nums = state['legal_actions']
        # state['legal_actions'] = collections.OrderedDict([( int(action_nums[0]), None), ( int(action_nums[1]), None), ( int(action_nums[2]), None)])
        # # state["legal_actions"] = collections.OrderedDict([state["legal_actions"]])
        # print("state:", state)
        # print("")

        info = agent_0.eval_step(state)
        print("action:", info[0])
        action = int(info[0])



        return action
        
 